﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Casemeet.Groups;
using VK.Comm;

namespace VK.Casemeet.Web.ShopAdmin.Groups
{
    public partial class CategoryEdit : System.Web.UI.Page
    {

        public int categoryID = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/ShopAdmin/Home.aspx"},
                new MapPath{ Text="商品",Url="CategoryList.aspx"},
                new MapPath{ Text="编辑分类",Url="#"}
            };
            categoryID = Util.GetQueryInt("CategoryID");
            if (!IsPostBack)
                LoadData();
        }

        internal void LoadData()
        {

            if (categoryID != 0)
            {
                CategoryEntity category = GroupsBLL.GetCategories(categoryID, "").First();
                txtName.Text = category.gc_name;
                chkIsEnable.Checked = category.gc_isenable;
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            CategoryEntity category = LoadEntity();
            category.gc_id = categoryID;

            if (GroupsBLL.UpdateCategory(category) > 0)
            {
                Message.Msg(this.Page, CS.MsgEditSuccess, MessageType.Success);
            }
            else
            {
                Message.Msg(this.Page, CS.MsgEditFailure, MessageType.Failure);
            }
            LoadData();
        }

        protected CategoryEntity LoadEntity()
        {
            CategoryEntity category = new CategoryEntity();
            category.gc_name = txtName.Text;
            category.gc_isenable = chkIsEnable.Checked;

            return category;
        }
    }
}